package cn.bincker.mybatis.encrypt.data.migration.entity;

import cn.bincker.mybatis.encrypt.entity.EncryptProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Objects;

@Data
@AllArgsConstructor
public class ColumnInfo {
    private String name;
    private String type;
    private Integer size;
    private boolean isPrimaryKey;
    private boolean nullable;
    private int index;
    private EncryptProperty encryptProperty;
    private ForeignKeyInfo foreignKey;

    public boolean isEncrypt(){
        return encryptProperty != null;
    }

    public String getSqlName(){
        return "\"" + name + "\"";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ColumnInfo that = (ColumnInfo) o;
        return Objects.equals(name, that.name) && Objects.equals(type, that.type) && Objects.equals(size, that.size);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
